package com.demo.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.demo.domain.PracticalAchievement;
import com.demo.domain.TeamComposition;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface PracticalAchievementDao extends BaseMapper<PracticalAchievement> {

    @Select("select pa_title from "
            + "tb_practical_achievement where "
            + "pa_id = #{paid}")
    String getTitleByid (long paid);

    @Select("<script>" +
            "SELECT pa_id,pa_title,pa_possessor_id,pa_possessor_name,pa_level,pa_advisor_id,pa_advisor_name,"
            + "pa_achieve_time,pa_description,pa_type,pa_teacher_flag FROM "
            + "tb_practical_achievement pa " +
            "where pa.pa_del_flag = 0" +
            "<if test='title != null and title != \"\"'>AND pa.pa_title = #{title}</if>" +
            "<if test='possessorName != null and possessorName != \"\"'>AND pa.pa_possessor_name = #{possessorName}</if>" +
            "<if test='advisorName != null and advisorName != \"\"'>AND pa.pa_advisor_name = #{advisorName}</if>" +
            " ORDER BY pa.pa_id ASC" +
            "</script>")
    @Results({
            @Result(column = "pa_id", property = "id"),
            @Result(column = "pa_title", property = "title"),
            @Result(column = "pa_possessor_id", property = "possessorId"),
            @Result(column = "pa_possessor_name", property = "possessorName"),
            @Result(column = "pa_level", property = "level"),
            @Result(column = "pa_advisor_id", property = "advisorId"),
            @Result(column = "pa_advisor_name", property = "advisorName"),
            @Result(column = "pa_achieve_time", property = "achieveTime"),
            @Result(column = "pa_description", property = "description"),
            @Result(column = "pa_type", property = "type"),
            @Result(column = "pa_teacher_flag", property = "teacherFlag")
    })
    List<PracticalAchievement> selectPracticalAchievementList(String title, String possessorName, String advisorName);

    @Select("\"SELECT pa_id,pa_title,pa_possessor_id,pa_possessor_name,pa_level,pa_advisor_id,pa_advisor_name,\"\n"
            + "            + \"pa_achieve_time,pa_description,pa_type,pa_teacher_flag FROM \"\n"
            + "            + \"tb_practical_achievement pa \" +\n"
            + "            \"where pa.pa_del_flag = 0\"")
    @Results({
            @Result(column = "pa_id", property = "id"),
            @Result(column = "pa_title", property = "title"),
            @Result(column = "pa_possessor_id", property = "possessorId"),
            @Result(column = "pa_possessor_name", property = "possessorName"),
            @Result(column = "pa_level", property = "level"),
            @Result(column = "pa_advisor_id", property = "advisorId"),
            @Result(column = "pa_advisor_name", property = "advisorName"),
            @Result(column = "pa_achieve_time", property = "achieveTime"),
            @Result(column = "pa_description", property = "description"),
            @Result(column = "pa_type", property = "type"),
            @Result(column = "pa_teacher_flag", property = "teacherFlag")
    })
    List<PracticalAchievement> listAllPracticalAchievement();

    @Update("UPDATE tb_practical_achievement pa set pa.pa_del_flag = 1 where pa.pa_id = #{id}")
    int deletePracticalAchievementById(PracticalAchievement practicalAchievement);

}
